//
//  DownLoadDetailViewController.m
//  MapleLeaf
//
//  Created by WangZe on 15/11/30.
//  Copyright © 2015年 AntennaBabyTeam. All rights reserved.
//

#import "DownLoadDetailViewController.h"
#import "DownLoadDetailTableViewCell.h"
#import "DownloadProgressViewController.h"
@interface DownLoadDetailViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong)UITableView *tableView;
@end

@implementation DownLoadDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"下载详情";
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    
}

- (UITableView *)tableView
{
    if (!_tableView) {
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [self.view addSubview:self.tableView];
        [self.tableView registerClass:[DownLoadDetailTableViewCell class] forCellReuseIdentifier:@"reuse"];
        self.tableView.rowHeight = 140;
    }
    return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DownLoadDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    NSMutableDictionary *dic = self.dataArr[indexPath.row];
    cell.nameLabel.text = dic[@"name"];
    NSString *str = [dic[@"pic"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];;
    
    [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"123.jpg"]];
    cell.stateLabel.text = dic[@"number"];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DownloadProgressViewController *VC = [[DownloadProgressViewController alloc] init];
    [self.navigationController pushViewController:VC animated:YES];
    VC.dataArr = self.dataArr[indexPath.row][@"detail"];
    VC.nameStr = self.dataArr[indexPath.row][@"name"];
    NSLog(@"%@", VC.dataArr);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
